<template>
<div class="enterpriseInfo">
  <el-descriptions :column="4" border v-if="model">
    <el-descriptions-item>
      <template slot="label">
        企业名称
      </template>
      {{ model.tenantName }}
    </el-descriptions-item>
    <el-descriptions-item>
      <template slot="label">
        负责人
      </template>
      {{ model.chargeUser }}
    </el-descriptions-item>
    <el-descriptions-item>
      <template slot="label">
        联系电话
      </template>
      {{ model.chargeUserMobile }}
    </el-descriptions-item>
    <el-descriptions-item>
      <template slot="label">
        统一信用编码
      </template>
      {{ model.socialCreditCode }}
    </el-descriptions-item>
    <el-descriptions-item>
      <template slot="label">
        营业执照编号
      </template>
      {{ model.businessLicense }}
    </el-descriptions-item>
    <el-descriptions-item>
      <template slot="label">
        备注信息
      </template>
      {{ model.remarks }}
    </el-descriptions-item>
  </el-descriptions>
  <div class="enterprise-content" v-if="tenantId">
    <el-button type="primary" size="mini" @click="saveInfo">保存企业简介</el-button>
    <y-rich-text
        v-model="content.content"
        placeholder="请输入企业简介"
        business-sys-module-code="ENTERPRISE_INFO"></y-rich-text>
  </div>
</div>
</template>

<script>
export default {
  name: "enterpriseInfo",
  data(){
    return {
      model: null,
      tenantId: '',
      content: {
        id: '',
        content: ''
      }
    }
  },
  created(){
    this.initTenantId();
    this.initInfo();
  },
  methods:{
    initTenantId(){
      let user = localStorage.getItem('user');
      if(user) {
        user = JSON.parse(user);
        this.tenantId = user.tenantId;
      }
    },
    initInfo(){
      if(this.tenantId){
        this.$yAxios({
          url: this.$api.system.queryTenantDetail,
          data:{
            id: this.tenantId
          },
          loading: true
        }, info => {
          this.$set(this, 'model', Object.gain(info.tenant, ['tenantName', 'socialCreditCode', 'businessLicense',
            'chargeUser', 'chargeUserMobile', 'remarks'], ''));
          if(info.content){
            this.content.content = info.content.content;
            this.content.id = info.content.id
          }
        })
      }
    },
    saveInfo(){
      this.$yAxios({
        url: this.$api.system.saveTenantDetail,
        data: {
          bizId: this.tenantId,
          ...this.content
        },
        loading: true,
      }, info => {
        this.$message({
          type: 'success',
          message: '保存成功'
        });
      })
    }
  }
}
</script>

<style scoped lang="less">
.enterpriseInfo{
  .enterprise-content{
    margin-top: 20px;
    position: relative;
    >.el-button{
      position: absolute;
      right: 10px;
      top: 7px;
    }
  }
}
</style>